function Customer() {
	var err=MSG.ERR;
	var dt/*弹出层内容*/, bg/*透明背景*/, _this;
	_this = this;
	this.init=function(){
		$('body').keydown(function(event){
			if(KEY.ESC == event.keyCode) {
				hide();
			}
		});
	};
	function hide() {
		aju.removeAll([dt,bg,$('.tip-yellow')]);
		$('#ajaxClose').remove();
	};
	function getRecord(cid) {
		var url = "/a/ajax/customer/account/record";
		bg = aju.ajaxBg(function() {
			aju.setOffsetDown(10);
			$.ajax({
				url:url
				,type:'GET'
				,data:{cid:cid}
				,success:function(data){
					dt = aju.ajaxData().css({'width':'60%'});
					dt.html('<div class="list">'+data+'</div>');
					aju.positionCenter(dt);
					// 显示关闭按钮并绑定关闭时间
					aju.ajaxClose(dt).click(function(){
						hide();
					});
				}
				,error:function(){
					alert(err);
				}
			});
		});
	};
	this.showAccount=function(id) {
		getRecord(id);
	};
	// 往来帐目查询
	this.accountSearch=function() {
		var url = "/a/ajax/customer/account/search";
		bg = aju.ajaxBg(function() {
			aju.setOffsetDown(80);
			$.ajax({
				url:url
				,type:'GET'
				,data:{}
				,success:function(data){
					dt = aju.ajaxData().css({'width':'390','height':'160'});
					dt.html('<div class="ajaxForm">'+data+'</div>');
					aju.positionCenter(dt);
					// 显示关闭按钮并绑定关闭时间
					aju.ajaxClose(dt).click(function(){
						hide();
					});
					$( ".ajaxForm #btime" ).datepicker({
						dateFormat:'yy-mm-dd'
						
					});
					$( ".ajaxForm #etime" ).datepicker({
						dateFormat:'yy-mm-dd'
						
					});
					$( ".ajaxForm input[type=submit]" ).click(function(){
						$(this).attr('disabled', 'disabled');
						var params="?"
							params+="btime="+$('#btime').val();
							params+="&etime="+$('#etime').val();
						window.location=('/a/customer/account/results'+params);
					});
				}
				,error:function(){
					alert(err);
				}
			});
		});
		return false;
	};
	// 销售对账查询
	this.billSearch=function(cid) {
		var url = "/a/ajax/customer/bill/search";
		bg = aju.ajaxBg(function() {
			aju.setOffsetDown(80);
			$.ajax({
				url:url
				,type:'GET'
				,data:{}
				,success:function(data){
					dt = aju.ajaxData().css({'width':'390','height':'160'});
					dt.html('<div class="ajaxForm">'+data+'</div>');
					aju.positionCenter(dt);
					// 显示关闭按钮并绑定关闭时间
					aju.ajaxClose(dt).click(function(){
						hide();
					});
					$( ".ajaxForm #btime" ).datepicker({
						dateFormat:'yy-mm-dd'
						
					});
					$( ".ajaxForm #etime" ).datepicker({
						dateFormat:'yy-mm-dd'
						
					});
					$( ".ajaxForm input[type=submit]" ).click(function(){
						$(this).attr('disabled', 'disabled');
						var params="?"
							params+="btime="+$('#btime').val();
							params+="&etime="+$('#etime').val();
							params+="&cid="+cid;
						window.location=('/a/customer/bill/results'+params);
					});
				}
				,error:function(){
					alert(err);
				}
			});
		});
		return false;
	};
}
var customer = new Customer();
$(function(){
	customer.init();
});